<template>
  <div>
    <el-tag>覆膜</el-tag>
    <el-checkbox @change="clickToChange()">需要</el-checkbox>
    <br/>
      <span>正面：</span>
      <el-select v-model="fumo.fu_mo_zheng_mian" :disabled="disable"
                 placeholder="请选择" class="length" size="small">
        <el-option v-for="item in option.fu_mo_option" :key="item" :label="item" :value="item"></el-option>
      </el-select>
      <span>反面：</span>
      <el-select v-model="fumo.fu_mo_fan_mian" :disabled="disable"
                 placeholder="请选择" class="length" size="small">
        <el-option v-for="item in option.fu_mo_option" :key="item" :label="item" :value="item"></el-option>
      </el-select>
    <br/>
    <template v-if="getRole()">
    <el-tag type="warning" class="cost">正面: {{computeCost()[0]}}</el-tag>
    <el-tag type="warning" class="cost">反面: {{computeCost()[1]}}</el-tag>
    </template>
  </div>
</template>

<script>
export default {
  name: 'Fumo',
  props: ['Q', 'x', 'y', 'confirm'],
  data () {
    return {
      disable: true,
      fumo: {
        fu_mo_zheng_mian: '',
        fu_mo_fan_mian: ''
      },
      option: {
        fu_mo_option: ['光膜', '哑膜', '干光膜', '干哑膜', '触感膜', '雪花膜', '防刮膜']
      }
    }
  },
  methods: {
    computeCost () {
      let x = parseInt(this.x)
      let y = parseInt(this.y)
      let q = parseInt(this.Q)
      let zhengPrice
      let zhengPriceStr
      let fanPrice
      let fanPriceStr
      let YList = [0.09, 0.1, 0.135, 0.7, 1.6, 0.7, 1.7]
      let moPrice = [0.4, 0.5, 0.6, 0.7, 1.6, 0.7, 1.7]
      let kaiPrice = [100, 100, 100, 120, 200, 150, 200]
      let YZheng = YList[this.option.fu_mo_option.indexOf(this.fumo.fu_mo_zheng_mian)]
      let YFan = YList[this.option.fu_mo_option.indexOf(this.fumo.fu_mo_fan_mian)]
      let moPZheng = moPrice[this.option.fu_mo_option.indexOf(this.fumo.fu_mo_zheng_mian)]
      let moPFan = moPrice[this.option.fu_mo_option.indexOf(this.fumo.fu_mo_fan_mian)]
      let m1 = (x + 15) * (y + 10) / Math.pow(10, 6)
      let m2 = (x + 10) * (y + 15) / Math.pow(10, 6)
      let m1Str = `(${x}+15)×(${y}+10)×(10^-6)`
      let m2Str = `(${x}+10)×(${y}+15)×(10^-6)`
      if (x <= y) {
        zhengPrice = m1 * moPZheng <= YZheng ? YZheng * q : m1 * moPZheng * q
        zhengPriceStr = m1 * moPZheng <= YZheng ? `${YZheng}×${q} = ${zhengPrice}` : m1Str + `×${moPZheng}×${q} = ${zhengPrice}`
        fanPrice = m1 * moPFan <= YFan ? YFan * q : m1 * moPFan * q
        fanPriceStr = m1 * moPFan <= YFan ? `${YFan}×${q} = ${fanPrice}` : m1Str + `×${moPFan}×${q} = ${fanPrice}`
      } else {
        zhengPrice = m2 * moPZheng <= YZheng ? YZheng * q : m2 * moPZheng * q
        zhengPriceStr = m2 * moPZheng <= YZheng ? `${YZheng}×${q} = ${zhengPrice}` : m2Str + `×${moPZheng}×${q} = ${zhengPrice}`
        fanPrice = m2 * moPFan <= YFan ? YFan * q : m2 * moPFan * q
        fanPriceStr = m2 * moPFan <= YFan ? `${YFan}×${q} = ${fanPrice}` : m2Str + `×${moPFan}×${q} = ${fanPrice}`
      }
      if (zhengPrice <= kaiPrice[this.option.fu_mo_option.indexOf(this.fumo.fu_mo_zheng_mian)]) {
        zhengPriceStr = `${kaiPrice[this.option.fu_mo_option.indexOf(this.fumo.fu_mo_zheng_mian)]} (成本小于开机费)`
      }
      if (fanPrice <= kaiPrice[this.option.fu_mo_option.indexOf(this.fumo.fu_mo_fan_mian)]) {
        fanPriceStr = `${kaiPrice[this.option.fu_mo_option.indexOf(this.fumo.fu_mo_fan_mian)]} (成本小于开机费)`
      }
      return [zhengPriceStr, fanPriceStr]
    },
    clickToFin () {
      if (!this.disable) this.$emit('transferToFather', 'fumo', this.fumo)
    },
    clickToChange () {
      this.disable = !this.disable
    },
    getRole () {
      return sessionStorage.getItem('roleType') === '1'
    }
  },
  watch: {
    confirm (nV, oV) {
      if (nV !== oV) this.clickToFin()
    }
  }
}
</script>

<style scoped>
.length{
  width: 100px;
  display: inline-block;
  margin-top: 10px;
  margin-right: 10px;
}

.cost{
  margin-top: 10px;
}
</style>
